#!/usr/bin/env python3

import multiprocessing as mp
import os
import time
import random

def Run(i, s):
    sec = random.randint(1, 5)
    s.append(sec)
    print("child[%d] sleep %d pid = %d" % (i, sec, os.getpid()))
    time.sleep(sec)
    print("child[%d] %d exit..." % (i, os.getpid()))

def main():
    s = []
    p = mp.Pool(5)

    for i in range(10):
        p.apply_async(Run, (i, s))

    p.close()
    p.join()

    print(s)


if __name__ == "__main__":
    main()
